package ysu.sxm.ptjc.Service.Impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ysu.sxm.ptjc.Dao.ProRelationInfoDao;
import ysu.sxm.ptjc.Dao.produceInfoDao;
import ysu.sxm.ptjc.Service.InsertInfoAndRelationService;
import ysu.sxm.ptjc.Service.UpdateProduceNumService;
import ysu.sxm.ptjc.pojo.ProRelationInfo;
import ysu.sxm.ptjc.pojo.ProduceInfo;

import java.nio.file.ProviderNotFoundException;
import java.sql.Date;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@Service
public class InsertInfoAndRelationServiceImpl implements InsertInfoAndRelationService {
    @Autowired
    ProRelationInfoDao proRelationInfoDao;


    @Autowired
    produceInfoDao pro;


    @Autowired
    UpdateProduceNumService updateProduceNumService;
    @Override
    public String setProRelation(String customerId,String color,String car,String workShop) {
        String UUid=updateProduceNumService.updateProduceNum();
        ProRelationInfo proRelationInfo=new ProRelationInfo();
        proRelationInfo.setCarTypeId(car);
        proRelationInfo.setColor(color);
        proRelationInfo.setWorkshopId(workShop);
        proRelationInfo.setProduceNum(UUid);
        proRelationInfo.setCustomerId(customerId);
        proRelationInfoDao.insertPro(proRelationInfo);
        return UUid;
    }

    @Override
    public ProduceInfo RetProduceInfo( String produce_type, Long lineId, String date, String Produce_name,String customerId,String color,String car,String workShop) throws ParseException {
        String UUid=setProRelation(customerId, color, car, workShop);
        ProduceInfo produceInfo=new ProduceInfo();
        produceInfo.setProduceNum(UUid);
        produceInfo.setProduceType(produce_type);
        produceInfo.setLineId(lineId);
        Timestamp time=new Timestamp(new SimpleDateFormat("yyyy-MM-dd").parse(date).getTime());
        produceInfo.setProduceDate(time);
        produceInfo.setProduceName(Produce_name);
        return produceInfo;
    }

    @Override
    public void setProduceInfo(Long group, ProduceInfo produceInfo) {
        produceInfo.setGroup(group);
        pro.insertProduceInfo(produceInfo);
    }
}
